import Mock from "mockjs";
import { MockMethod } from "vite-plugin-mock";
import utils from "../../../src/utils/utils";
import contextPath from "../../context-path";
const Random = Mock.Random;

export default [
  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/log.listing",
    method: "post",
    response: (options) => {
      const rows: any[] = [];
      const total = 112;
      let cnt = options.body.rows;
      if (options.body.rows * options.body.page > total) {
        cnt = total - options.body.rows * (options.body.page - 1);
      }
      for (let i = 0; i < cnt; i++) {
        const template = {
          logId: Random.guid(),
          catagory: Mock.mock({
            "array|1": ["app", "sys", "client"],
          }).array,
          logAction: Mock.mock({
            "array|1": ["INSERT", "UPDATE", "SEARCH", "EXPORT", "DELETE"],
          }).array,
          logLevel: Mock.mock({
            "array|1": [0, 1, 2],
          }).array,
          logInfo: Random.cparagraph(),
          businessKey: Random.guid(),
          hostId: Random.guid(),
          ipAddress: Random.ip(),
          createAccountName: Random.cname(),
          createTime: Random.datetime(),
        };
        rows.push(template);
      }

      return {
        code: 200,
        total: total,
        rows: rows,
      };
    },
  },
  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/log.get",
    method: "post",
    response: (options) => {
      const template = {
        logId: Random.guid(),
        catagory: Mock.mock({
          "array|1": ["app", "sys", "client"],
        }).array,
        logAction: Mock.mock({
          "array|1": ["INSERT", "UPDATE", "SEARCH", "EXPORT", "DELETE"],
        }).array,
        logLevel: Mock.mock({
          "array|1": [0, 1, 2],
        }).array,
        logInfo: Random.cparagraph(),
        businessKey: Random.guid(),
        hostId: Random.guid(),
        ipAddress: Random.ip(),
        createAccountName: Random.cname(),
        createTime: Random.datetime(),
      };

      return {
        code: 200,
        message: "",
        data: template,
      };
    },
  },
  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/log.prev.get",
    method: "post",
    response: (options) => {
      const template = {
        logId: Random.guid(),
        catagory: Mock.mock({
          "array|1": ["app", "sys", "client"],
        }).array,
        logAction: Mock.mock({
          "array|1": ["INSERT", "UPDATE", "SEARCH", "EXPORT", "DELETE"],
        }).array,
        logLevel: Mock.mock({
          "array|1": [0, 1, 2],
        }).array,
        logInfo: Random.cparagraph(),
        businessKey: Random.guid(),
        hostId: Random.guid(),
        ipAddress: Random.ip(),
        createAccountName: Random.cname(),
        createTime: Random.datetime(),
      };

      return {
        code: 200,
        message: "",
        data: template,
      };
    },
  },
  {
    url: contextPath.VITE_API_ADMIN_CONTEXT_PATH + "/admin/api/log.next.get",
    method: "post",
    response: (options) => {
      const template = {
        logId: Random.guid(),
        catagory: Mock.mock({
          "array|1": ["app", "sys", "client"],
        }).array,
        logAction: Mock.mock({
          "array|1": ["INSERT", "UPDATE", "SEARCH", "EXPORT", "DELETE"],
        }).array,
        logLevel: Mock.mock({
          "array|1": [0, 1, 2],
        }).array,
        logInfo: Random.cparagraph(),
        businessKey: Random.guid(),
        hostId: Random.guid(),
        ipAddress: Random.ip(),
        createAccountName: Random.cname(),
        createTime: Random.datetime(),
      };

      return {
        code: 200,
        message: "",
        data: template,
      };
    },
  },
] as MockMethod[];
